//
// Created by yuping.li on 10/17/24.
//

#ifndef CONTEXT_H_
#define CONTEXT_H_

#ifdef __cplusplus
extern "C" {
#endif

#include "stdint.h"

typedef struct {
  uintptr_t r0;
  uintptr_t r1;
  uintptr_t r2;
  uintptr_t r3;
  uintptr_t r4;
  uintptr_t r5;
  uintptr_t r6;
  uintptr_t r7;
  uintptr_t r8;
  uintptr_t r9;
  uintptr_t r10;
  uintptr_t r11;
  uintptr_t sp;
  uintptr_t lr;
  uintptr_t r12;
  uintptr_t pc;
} regs_t;

typedef struct {
  void *ss_sp;
  uint32_t ss_size;
} stack_t;

typedef struct {
  regs_t reg;
  stack_t stack;
} lcontext_t;

int32_t get_context(lcontext_t *);
int32_t set_context(const lcontext_t *);
void make_context(lcontext_t *, void *func, int32_t argc, ...);
int32_t swap_context(lcontext_t *, const lcontext_t *);

#ifdef __cplusplus
}
#endif

#endif //CONTEXT_H_
